using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering.Universal;

namespace FrameWork.Weather
{
    public class SceneWeatherManager : SingletonMonoBehaviour<SceneWeatherManager>
    {
        [Header("雨雪天气的粒子")]
        [SerializeField] private GameObject rainy;           // 下雨粒子
        [SerializeField] private GameObject snowy;           // 下雪粒子
        
        // [Header("全局灯光效果")]
        // [SerializeField] private WorldLightManager worldLightManager;
        
        // [Header("灯光影响因子")]
        // [SerializeField] private float rainyIntensity;       // 下雨
        // [SerializeField] private float snowyIntensity;       // 下雪
        // [SerializeField] private float cloudyIntensity;      // 阴天
        // [SerializeField] private float thunderstormIntensity;// 雷阵雨
        // [SerializeField] private float windyIntensity;       // 刮风
        // [SerializeField] private float hailIntensity;        // 冰雹
        protected override void Awake()
        {
            base.Awake();
        }

        public void ApplyWeatherEffects(WeatherState state)
        {
            // 清空前一天天气效果
            ClearAll();
            // 启动协程
            StartCoroutine(DelayedAction(state));
        }

        IEnumerator DelayedAction(WeatherState state)
        {
            // 延迟一秒
            yield return new WaitForSeconds(0.5f);
            switch (state)
            {
                case WeatherState.Rainy: Rainy(); break;
                case WeatherState.Snowy: Snowy(); break;
                case WeatherState.Sunny: Sunny(); break;
                case WeatherState.Cloudy: Cloudy(); break;
                case WeatherState.Thunderstorm: Thunderstorm(); break;
                case WeatherState.Windy: Windy(); break;
                case WeatherState.Hail: Hail(); break;
            }
        }

        /// <summary>
        /// 清空昨天的天气状况
        /// </summary>
        private void ClearAll()
        {
            // 关闭粒子特效
            rainy.SetActive(false);
            snowy.SetActive(false);
            // 停止打雷
            // worldLightManager.StopThunderstorm();
        }

        // EventSystem.Instance.EventTrigger(EventName.EVENT_SYSTEM_ADD_TIPS, "");
        #region Behavior function

        /// <summary>
        /// 下雨
        /// </summary>
        private void Rainy()
        {
            // print("下雨");
            rainy.SetActive(true);
            EventSystem.Instance.EventTrigger(EventName.EVENT_SYSTEM_ADD_TIPS, "今日下雨！");
            // worldLightManager.SetLightIntensity(rainyIntensity);
        }

        /// <summary>
        /// 下雪
        /// </summary>
        private void Snowy()
        {
            // print("下雪");
            snowy.SetActive(true);
            EventSystem.Instance.EventTrigger(EventName.EVENT_SYSTEM_ADD_TIPS, "今日下雪！");
            // worldLightManager.SetLightIntensity(snowyIntensity);
        }
        
        /// <summary>
        /// 晴天
        /// </summary>
        private void Sunny()
        {
            // print("晴天");
            EventSystem.Instance.EventTrigger(EventName.EVENT_SYSTEM_ADD_TIPS, "今日晴天！");
            // worldLightManager.SetLightIntensity(1);
        }
        
        /// <summary>
        /// 阴天
        /// </summary>
        private void Cloudy()
        {
            // print("阴天");
            EventSystem.Instance.EventTrigger(EventName.EVENT_SYSTEM_ADD_TIPS, "今日阴天！");
            // worldLightManager.SetLightIntensity(cloudyIntensity);
        }
        
        /// <summary>
        /// 雷阵雨
        /// </summary>
        private void Thunderstorm()
        {
            // print("雷阵雨");
            rainy.SetActive(true);
            EventSystem.Instance.EventTrigger(EventName.EVENT_SYSTEM_ADD_TIPS, "今日雷阵雨！");
            // worldLightManager.SetLightIntensity(thunderstormIntensity);
            // worldLightManager.StartThunderstorm();
        }
        
        /// <summary>
        /// 刮风
        /// </summary>
        private void Windy()
        {
            // print("刮风");
            EventSystem.Instance.EventTrigger(EventName.EVENT_SYSTEM_ADD_TIPS, "今日刮风！");
            // worldLightManager.SetLightIntensity(windyIntensity);
        }
        
        /// <summary>
        /// 冰雹
        /// </summary>
        private void Hail()
        {
            // print("冰雹");
            EventSystem.Instance.EventTrigger(EventName.EVENT_SYSTEM_ADD_TIPS, "今日冰雹！");
            // worldLightManager.SetLightIntensity(hailIntensity);
        }
    }

    #endregion
}
